package com.ad.base;

import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Cookies;
import org.apache.tapestry5.services.Request;

import com.ad.system.Common;

public class AbstractPage {

	// private static Logger log = Logger.getLogger(AbstractPage.class);

	@Inject
	private Request request;

	@Environmental
	private RenderSupport renderSupport;

	@Inject
	private Cookies cookies;

	public Request getRequest() {
		return request;
	}

	public RenderSupport getRenderSupport() {
		return renderSupport;
	}

	public Cookies getCookies() {
		return cookies;
	}

	protected void setupRender() {
		String className = this.getClass().getName();
		String cutFormer = className.split("com.ad.pages.")[1];
		StringBuffer upperPath = new StringBuffer();
		for (int i = 0; i < cutFormer.length(); i++) {
			if (cutFormer.charAt(i) == '.') {
				upperPath.append("../");
			}
		}
		renderSupport.addScriptLink(upperPath + "js/jquery-1.4.4.min.js");
		renderSupport.addScriptLink(upperPath + "js/common.js");

		renderSupport.addStylesheetLink(upperPath + "css/global.css", null);
		String userAgent = request.getHeader("user-agent");
		String cssURL = "";
		if (userAgent.contains("MSIE 6.0")) {
			cssURL = "css/ie6.css";
		} else if (userAgent.contains("MSIE 7.0")) {
			cssURL = "css/ie7.css";
		}
		if (!Common.isEmpty(cssURL)) {
			renderSupport.addStylesheetLink(upperPath + cssURL, null);
		}
	}
}
